package com.jiangnan.ui.activity

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProvider
import com.jiangnan.R
import com.jiangnan.databinding.ActivityCertificateBinding
import com.jiangnan.util.SharedPrefUtil
import com.jiangnan.util.ToastUtil
import com.jiangnan.viewmodel.UserViewModel

class CertificateActivity : AppCompatActivity() {

    private lateinit var viewmodel : UserViewModel
    private lateinit var binding : ActivityCertificateBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_certificate)
        binding = DataBindingUtil.setContentView(this, R.layout.activity_certificate)


        viewmodel = ViewModelProvider(this)[UserViewModel::class.java]

        viewmodel.loadUserCertificate(SharedPrefUtil.getLoginInfo(this)!!.id.toLong())

        viewmodel.userCertificate.observe(this){
            binding.tvAuthorityName.setText(it.authorityName)
            binding.tvMaxBorrowNum.setText(it.maxBorrowBookNum.toString() + "本")
            binding.tvMaxBorrowDay.setText(it.maxBorrowDay.toString() + "天")
            binding.tvOverduePay.setText("¥"+it.overduePayPerDay.toString()+"/天")
        }
        viewmodel.toastMessage.observe(this){
            ToastUtil.showShort(this, it)
        }
    }


}